package user.lan.com.usercenter;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.io.File;

import butterknife.BindView;
import user.lan.com.inherit.ParentActivity;
import user.lan.com.ui.CircleImageView;
import user.lan.com.util.GlideUtils;
import user.lan.com.util.ImageUtils;

public class Main2Activity extends ParentActivity {
    @BindView(R.id.iv_head2)
    CircleImageView image_head;

    protected Bitmap bitmap;
    @Override
    protected int getResourcesId() {
        return R.layout.activity_main2;
    }

    @Override
    protected boolean isFullScreen() {
        return false;
    }

    @Override
    protected void setFullScreen() {

    }

    @Override
    protected void init(Bundle savedInstanceState) {
        String url=getIntent().getStringExtra("url");
        Log.e(TAG,url);
        GlideUtils.loadImage(url,mContext,image_head);
        image_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImageUtils.takeOrChoosePhoto(Main2Activity.this,ImageUtils.TAKE_OR_CHOOSE_PHOTO);
            }
        });
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case ImageUtils.TAKE_OR_CHOOSE_PHOTO:
                //获取到了原始图片
                File f = ImageUtils.getPhotoFromResult(this, data);
                //裁剪方法
                ImageUtils.doCropPhoto(Main2Activity.this, f);
                break;
            case ImageUtils.PHOTO_PICKED_WITH_DATA:
                //获取到剪裁后的图片
                bitmap = ImageUtils.getCroppedImage();
                image_head.setImageBitmap(bitmap);
                if (bitmap!=null){
                    //TODO 这里可以执行上传头像方法
                }
                break;
        }
    }
}
